package com.zz.common.zid

import java.time.Instant
import java.util.UUID

import scala.concurrent.{ExecutionContext, Future}

import cats.data.OptionT
import com.zz.ady.idl.IdType
import com.zz.common.cassandra.CassandraConfig
import com.zz.common.dao.CassandraDAO
import com.zz.common.service.IdService.Zid
import com.zz.idl.{IdBundle, IdBundleMeta, ReversedIndexMeta, ZidIndex}

//object ScyllaSidStorage {
//
//  private[this] def listOf(s: String): List[String] = if (s.nonEmpty) s :: Nil else Nil
//
//  def storeIdBundleToZidIndex(bundle: IdBundle): ZidIndex =
//    ZidIndex(
//        id = UUID.fromString(bundle.zid)
//      , updatedAt = Instant.now()
//      , imei = listOf(bundle.imei)
//      , imeiMd5 = listOf(bundle.imeiMd5)
//      , imeiSha1 = listOf(bundle.imeiSha1)
//      , imsi = listOf(bundle.imsi)
//      , imsiMd5 = listOf(bundle.imsiMd5)
//      , imsiSha1 = listOf(bundle.imsiSha1)
//      , androidId = listOf(bundle.androidId)
//      , androidIdMd5 = listOf(bundle.androidIdMd5)
//      , androidIdSha1 = listOf(bundle.androidIdSha1)
//      , mac = listOf(bundle.mac)
//      , macMd5 = listOf(bundle.macMd5)
//      , macSha1 = listOf(bundle.macSha1)
//      , sn = listOf(bundle.sn)
//      , idfa = listOf(bundle.idfa)
//      , idfv = listOf(bundle.idfv)
//      , mid = listOf(bundle.mid)
//      , oaid = listOf(bundle.oaid)
//    )
//
//}
//
//class ScyllaSidStorage(cassandraConfig: CassandraConfig)(implicit ec: ExecutionContext) extends ZidStorage[Future] {
//
//  import ScyllaSidStorage._
//
//  protected val dao = CassandraDAO(cassandraConfig)
//
////  override def storeIdBundle(idBundle: IdBundle, idBundleMeta: IdBundleMeta): Future[Unit] = {
////    val zid = UUID.fromString(idBundle.zid)
////    dao.findZidIndex(zid).flatMap {
////      case None    =>
////        val index = storeIdBundleToZidIndex(idBundle)
////        dao.writeZidIndex(index)
////      case Some(x) =>
////
////    }
////  }
//
//  override def storeReversedIndex(id: String, idType: IdType, zid: String, reversedIndexMeta: ReversedIndexMeta): Future[Unit] = ???
//
//  override def queryZidInfo(zid: String): OptionT[Future, (IdBundle, IdBundleMeta)] = ???
//
//  override def queryZids(id: String, idType: IdType): OptionT[Future, (Zid, Seq[Zid], ReversedIndexMeta)] = ???
//
//  override def storeIdBundle(idBundle: IdBundle, idBundleMeta: IdBundleMeta): Future[Unit] = ???
//}
//
//
//object ZidIndexMonoid {
//  import cats.Monoid
//  implicit val zidIndexMonoid = new Monoid[ZidIndex] {
//    override def empty: ZidIndex = ZidIndex.defaultInstance
//    override def combine(x: ZidIndex, y: ZidIndex): ZidIndex = ???
//  }
//}